﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Core.DataAccess.IRepositories;

namespace Core.DataAccess.Repositories
{
    [Export(typeof(ICommentRepository))]
    public class CommentRepository : ICommentRepository
    {
        private Connection conn;
        public CommentRepository()
        {
            conn = new Connection();
        }

        public void SaveComment(Comment commentObj)
        {
            using (MXHEntities context = conn.GetContext())
            {
                if (commentObj != null)
                {
                    context.Comments.AddObject(commentObj);
                    context.SaveChanges();
                }
            }
        }


        public List<Comment> GetCommentBySytemObject(int sytemObjectID, long sytemObjectRecordID)
        {
            List<Comment> result = null;
            using (MXHEntities context = conn.GetContext())
            {
                result = context.Comments.Where(n => n.SystemObjectID == sytemObjectID && n.SystemObjectRecordID == sytemObjectRecordID)
                    .OrderByDescending(n => n.CreateDate).ToList();
            }
            return result;
        }
    }
}
